#include <iostream>
#include <string>
#include <cstdlib>
#include <map>

#include "hunterAPI.hpp"
#include "hunterHTTP.hpp"

using namespace std;

int main()
{
	HunterAPI::HiveMind hm("./database");
	freopen("./log", "w+", stderr);

	string cookie = getCookie();
	
	int id = -1;
	if (hm.verifyCookie(cookie, id) || id == -1)
	// login failed
	{
		cout << "Content-type: text/html;\n\n";
		o_header("Fail");
		o_login_error("Session expired w/ " + cookie);
		o_footer();
		return 0;
	}
	
	HunterAPI::Player pl;
	hm.getPlayerById(id, pl);

	// stats page goes here
	vector <HunterAPI::Player> plys;
	hm.getTopNPlayers(plys);
	
	cout << "Content-type: text/html;\n\n";	
	o_header("Club -- Stats");
	o_upper_visible(pl);

	o_stat_player_header();
	for (int i = 0; i < plys.size(); i++)
	{
		o_stat_player(plys[i], i, hm);
	}
	o_stat_player_footer();
	
	o_footer();
	
	return 0;
}
